import 'package:flutter/material.dart';
import 'package:wechat_clone/modal/addressbook.dart' show mockAddressBook, AddressBook;

class _AddressBookItem extends StatelessWidget {
  _AddressBookItem({this.addressBook});
  final AddressBook addressBook;

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border( bottom: BorderSide(color: Color(0xffd9d9d9), width: 0.5)),
      ),
      padding: const EdgeInsets.all(10.0),
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          addressBook.avatar.startsWith('assets')
          ? Image.asset(
              addressBook.avatar,
              width: 48.0,
            )
          : Image.network(
              addressBook.avatar,
              width: 48.0,
            ), 
          // Image.asset('assets/images/ic_tx_news.png', width: 48.0,),
          Container(width: 10.0,),
          Text('${addressBook.title}', style: TextStyle(color: Color(0xff353535), fontSize: 16.0, fontWeight: FontWeight.w500),)
        ], 
      ),  
    );
  }
}

class AddressBookPage extends StatefulWidget {
  @override
  _AddressBookPageState createState() => _AddressBookPageState();
}

class _AddressBookPageState extends State<AddressBookPage> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemCount: mockAddressBook.length,
      itemBuilder: (BuildContext context, int index){
        return _AddressBookItem( addressBook: mockAddressBook[index],);
      }, 
    );
  }
}